//
//  IntExtension.swift
//  WalkNovel
//
//  Created by Kevin on 2023/7/4.
//

import UIKit

extension Int {
    func wn_toCountdown() -> String {
        var h = 0
        var m = 0
        var s = 0
        if self > 3600 {
            h = self / 3600
            m = self % 3600 / 60
            s = self % 60
        }else {
            m = self / 60
            s = self % 60
        }

        if h == 0 {
            if m == 0 {
                if s == 0 {
                    return ""
                }else {
                    return String(format: "00:%02d", s)
                }
            }else {
                if s == 0 {
                    return String(format: "%02d:00", m)
                }else {
                    return String(format: "%02d:%02d", m, s)
                }
            }
        }else {
            if m == 0 {
                if s == 0 {
                    return String(format: "%02d:00:00", h)
                }else {
                    return String(format: "%02d:00:%02d", h, s)
                }
            }else {
                if s == 0 {
                    return String(format: "%02d:%02d:00", h, m)
                }else {
                    return String(format: "%02d:%02d:%02d", h, m, s)
                }
            }
        }
    }
}

